<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>销售出库单</title>
	<jsp:include page="easyuiIncludeJS.jsp"></jsp:include>
</head>
<body>
   <script type="text/javascript">
   var startrow=0;
	$(function(){
			var pager = $(".easyui-datagrid").datagrid('getPager');
			$(pager).pagination({
				total:${pager.totalRows},
				pageSize:${pager.pageRow},
				displayMsg:'{from}-{to}/{total}',
				pageNumber:${pager.cur_page},
				afterPageText:'页，共{pages}页',
				pageList:[5,10,20,30,50,100],
				loading:false,
				showPageList:true,
				showRefresh:true,
				//刷新方法
				onBeforeRefresh:function(p,s){
					location.href="${pageContext.request.contextPath }/admin/sale/list?cur_page="+p+"&pageRow="+s;
				},
				onSelectPage:function(p,s){
					location.href="${pageContext.request.contextPath }/admin/sale/list?cur_page="+p+"&pageRow="+s;
				}
			});
			$('#changesize').datagrid('resize', {
				height:document.body.clientHeight-60
			});
		});	

		function save(){
			document.forms[1].submit();
		}
		
		function add(){
			var url="${pageContext.request.contextPath }/admin/sale/init?orderType=3";
			var title="销售出库新增";
			addTab1(title, url);
		}
		function del(){
			var ids = $('input[name="orderNo"]:checked');
			var len = ids.length;
			if(ids.length==0){
				alert("请选择要删除的单据");
				return;
			}
			if(!confirm('删除确认')){
				return;
			}			
			var arr="";
			ids.each(function(i,d){
				if((i+1)!=len){
					arr += $(d).val()+",";
				}else{
					arr += $(d).val();
				}
			})
			var url = "${pageContext.request.contextPath }/admin/sale/del?ids="+arr;
			location.href=url;	
		}
		function status(){		
			var ids = $('input[name="orderNo"]:checked');
			var len = ids.length;
			if(ids.length==0){
				alert("请选择要作废的单据");
				return;
			}
			if(!confirm('作废单据确认')){
				return false;
			}
			var arr="";
			ids.each(function(i,d){
				if((i+1)!=len){
					arr += $(d).val()+",";
				}else{
					arr += $(d).val();
				}
			})
			var url = "${pageContext.request.contextPath }/admin/sale/status?ids="+arr;
			location.href=url;	
			
		}
		function aduit(){		
			var ids = $('input[name="orderNo"]:checked');
			var len = ids.length;
			if(ids.length==0){
				alert("请选择要审核的单据");
				return;
			}
			if(!confirm('审核单据确认')){
				return false;
			}
			var arr="";
			ids.each(function(i,d){
				if((i+1)!=len){
					arr += $(d).val()+",";
				}else{
					arr += $(d).val();
				}
			})
			var url = "${pageContext.request.contextPath }/admin/sale/aduit?ids="+arr;
			location.href=url;	
		}
		function edit(){		
			var ids = $('input[name="orderNo"]:checked');
			var len = ids.length;
			if(ids.length==0){
				alert("请选择要查看的单据");
				return;
			}
			if(ids.length>1){
				alert("只能选择一张单据");
				return;
			}
			var arr="";
			ids.each(function(i,d){
				if((i+1)!=len){
					arr += $(d).val()+",";
				}else{
					arr += $(d).val();
				}
			})
			var url = "${pageContext.request.contextPath }/admin/sale/update?orderNo="+arr;
			var title="销售出库维护"+arr;
			addTab1(title, url);
			//location.href=url;	
		}

		if("${errinfo}"!=null&&"${errinfo}".length>0){
			alert("${errinfo}");
		}
	</script>
	<form action="${pageContext.request.contextPath }/admin/sale/list" method="post">
	<table width="100%" border="0" cellpadding="0" cellspacing="0" BACKGROUND="images/maintitle.jpg">
	<tr>
		<td align="left">
			<a class="easyui-linkbutton" plain="true" icon="icon-add" href="javascript:void(0);" onclick="add();">添加</a>
			<a class="easyui-linkbutton" plain="true" icon="icon-cut" href="javascript:void(0);" onclick="del();">删除</a>
			<a class="easyui-linkbutton" plain="true" icon="icon-redo" href="javascript:void(0);" onclick="status();">作废</a>
			<a class="easyui-linkbutton" plain="true" href="javascript:void(0);" onclick="aduit()">审核</a>
			<a class="easyui-linkbutton" plain="true" href="javascript:void(0);" onclick="edit();">单据详情</a>
		</td>
	</tr>
	<tr>
		<td align="right">
			供应商<select name="supplierId" id="supplierId" style="width:320px">
					<option value="0">不选择</option>
					<c:forEach items="${supplierList }" var="d">
						<c:if test="${ord.supplierId==d.supplierId }">
							<option value="${d.supplierId}" selected="selected">(${d.supplierCode})${d.supplierName}</option>
						</c:if>
						<c:if test="${ord.supplierId!=d.supplierId }">
							<option value="${d.supplierId}">(${d.supplierCode})${d.supplierName}</option>
						</c:if>

					</c:forEach>
				</select>
				单据状态
				<select name="invalid" id="invalid"  style="width:70px"> 
						<option value="-1" <c:if test="${ord.invalid==-1}">selected</c:if>>不选择</option>
						<option value="1" <c:if test="${ord.invalid==1}">selected</c:if>>有效</option>
						<option value="0" <c:if test="${ord.invalid==0}">selected</c:if>>作废</option>
					</select>
				审核状态
				<select name="aduitStatus" id="aduitStatus"  style="width:70px"> 
						<option value="-1" <c:if test="${ord.aduitStatus==-1}">selected</c:if>>不选择</option>
						<option value="1" <c:if test="${ord.aduitStatus==1}">selected</c:if>>已审核</option>
						<option value="0" <c:if test="${ord.aduitStatus==0}">selected</c:if>>未审核</option>
					</select>
				开单人<input type="text" name="empName" id="empName" value="${ord.empName}" style="width:80px">
				时间<input type="text" class="easyui-datebox" name="orderDate" id="orderDate" value="${ord.orderDate }"  style="width:100px">
				-<input type="text" class="easyui-datebox" name="orderDate2" id="orderDate2"  value="${ord.orderDate2 }" style="width:100px">
			<input type="submit" value="查询">
		</td>
	</tr>
	</table>
	</form>
	<table class="easyui-datagrid" pagination="true"   id="changesize" style="width:auto;height:420px"  singleSelect="false">
			<thead>
			<tr>
				<th field="orderNo" checkbox="true" >选择</th>
				<th field="orderType" align="center" width="70">单据类型</th>
				<th field="orderNo1" align="center" width="140">单据编号</th>
				<th field="orderDate" align="center" width="90">单据日期</th>
				<th field="supplierName" align="center" width="150">供应商</th>
				<th field="empName" align="center" width="80">开单人</th>
				<th field="oprDate" align="center" width="150">开单时间</th>
				<th field="invalid" align="center" width="60">单据状态</th>
				<th field="aduitStatus" align="center" width="60">审核状态</th>
				<th field="materialCode" align="center" width="60">物料编码</th>
				<th field="materialName" align="center" width="80">物料名称</th>
				<th field="batchNo" align="center" width="140">批号</th>
				<th field="style" align="center" width="60">规格</th>
				<th field="storageName" align="center" width="60">仓库</th>
				<th field="materialUnit" align="center" width="60">单位</th>
				<th field="orderCnt" align="center" width="60">数量</th>
				<th field="orderFlag" align="center" width="60">冲红</th>
				<th field="aduitPerson" align="center" width="80">审核人</th>
				<th field="aduitDate" align="center" width="140">审核时间</th>
			</tr>
			</thead>
			<tbody>
				<c:forEach items="${pager.datas}" var="d">
					<c:forEach items="${d.detailList}" var="dd">
					<tr>
						<td>${d.orderNo }</td>
						<td>
							<c:if test="${d.orderType==1}">采购入库单</c:if>
							<c:if test="${d.orderType==2}">采购退货单</c:if>
							<c:if test="${d.orderType==3}">销售出库单</c:if>
							<c:if test="${d.orderType==4}">销售退货单</c:if>
							<c:if test="${d.orderType==5}">盘点损益单</c:if>
						</td>
						<td>${d.orderNo}</td>
						<td>${d.orderDate.substring(0,10)}</td>
						<td>${d.supplierName}</td>
						<td>${d.empName}</td>
						<td>${d.oprDate}</td>
						<td>
						<c:if test="${d.invalid==1}">有效</c:if>
						<c:if test="${d.invalid==0}">作废</c:if>
						</td>
						<td>
						<c:if test="${d.aduitStatus==1}">已审核</c:if>
						<c:if test="${d.aduitStatus==0}">未审核</c:if>
						</td>
						<td>${dd.materialCode}</td>
						<td>${dd.materialName}</td>
						<td>${dd.batchNo}</td>
						<td>${dd.style}</td>
						<td>${dd.storageName}</td>
						<td>${dd.materialUnit}</td>
						<td>${dd.orderCnt}</td>
						<td>${dd.orderFlag}</td>
						<td>${d.aduitPerson}</td>
						<td>${d.aduitDate}</td>
					</tr>
					</c:forEach>
				</c:forEach>
			</tbody>
		</table>	
	</body>
</html>